<admintpl file="header" />
</head>
<body>
    <div class="wrap">
        <ul class="nav nav-tabs">
            <li class="active"><a href="{:U('AdminServer/index')}">服务器列表</a></li>
        </ul>
        <form class="well form-search" method="post" action="">
            类型： 
            <select name="type" style="width: 120px;" class="status"  id="type" >
                <option value="0">大厅服务器</option>
                <php>
                    $map['zt']='1';
                    $gamelist=M('game')->where($map)->select();
                </php>
                <foreach name="gamelist" item="one">
                    <option value="{$one.id}">{$one.name}服务器</option>
                </foreach>
            </select> &nbsp;&nbsp;
            名称：
            <input type="text" name="title" id="title"  style="width: 200px;">
            端口: 
            <input type="text" name="dk" id="dk" style="width: 200px;" value="" placeholder="请输端口号...">
            <input type="button" class="btn btn-primary" value="添加" onclick="addserver()">
        </form>
            <table class="table table-hover table-bordered table-list">
                <thead>
                    <tr>
                        <th>服务器id</th>
                        <th>服务器名称</th>
                        <th>服务器类型</th>
                        <th>服务器状态</th>
                        <th>房间数量</th>
                        <th>端口号</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody id="list">
                </tbody>

            </table>
    </div>
      <script src="/index.php/admin/index/serverjs" type="text/javascript"></script>  
    <script>
    var websocket = new WebSocket("ws://<php>echo $_SERVER['HTTP_HOST'];</php>:"+dkxx);
    websocket.onmessage = function(event) {
        zdata=JSON.parse(event.data);
        console.log(zdata);
        window[zdata.act](zdata.msg);
    };
    websocket.onopen = function(event) {
            list();
    }
    function addserver(){
        var fs = {};
        fs.title=$("#title").val();
        fs.dk=$("#dk").val();
        fs.type=$("#type").val();
        fs.act='add';
        var jsonStr = JSON.stringify(fs);
        websocket.send(jsonStr);
    }
    function openserver(id){
        var fs = {};
        fs.id=id;
        fs.act='open';
        var jsonStr = JSON.stringify(fs);
        websocket.send(jsonStr);

    }
    function closeserver(id){
        var fs = {};
        fs.id=id;
        fs.act='close';
        var jsonStr = JSON.stringify(fs);
        websocket.send(jsonStr);

    }
    function del(id){
        var fs = {};
        fs.id=id;
        fs.act='del';
        var jsonStr = JSON.stringify(fs);
        websocket.send(jsonStr);
    }
    function list(){
        var fs = {};
        fs.act='init';
        fs.key='zmm123';
        fs.next='list';
        var jsonStr = JSON.stringify(fs);
        websocket.send(jsonStr);
    }
    function html(data){
        $('#list').html(data);
    }
    function error(data){
            alert(data);
    }
    function success(data){
            if(data){
                alert(data);
                $("#type").val(0);
                $("#dk").val('');
                $("#title").val('');
            }
            list();
    }
    </script>
    <script src="__PUBLIC__/js/common.js"></script>
</body>
</html>